//
//  SearchView.m
//  dhfsAPP
//
//  Created by Devil on 2017/8/7.
//  Copyright © 2017年 Devil. All rights reserved.
//

#import "SearchView.h"
@interface SearchView()

@property(nonatomic,strong)UIImageView *searchBtnView;

@end

@implementation SearchView
#pragma mark - 懒加载
-(HeaderView *)headerView{
    if (!_headerView) {
        _headerView = [[HeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, HEIGHT(128)) Title:@""];
        
        [_headerView addSubview:self.searchBtnView];
    }
    
    return _headerView;
}

-(UIImageView *)searchBtnView{
    if (!_searchBtnView) {
        _searchBtnView = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH(88), HEIGHT(52), WIDTH(642), HEIGHT(65))];
        
        _searchBtnView.image = [UIImage imageNamed:@"搜索框"];
        
        _searchBtnView.userInteractionEnabled = YES;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(search)];
        
        [_searchBtnView addGestureRecognizer:tap];
        
        [_searchBtnView addSubview:self.searchContentTextField];
        
        UIImageView *searchImg = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH(13), 0, WIDTH(41), HEIGHT(42))];
        
        searchImg.image = [UIImage imageNamed:@"搜索-蓝"];
        
        searchImg.center = CGPointMake(searchImg.center.x, self.searchContentTextField.center.y);
        
        [_searchBtnView addSubview:searchImg];
    }
    
    return _searchBtnView;
}

-(UITextField *)searchContentTextField{
    if (!_searchContentTextField) {
        _searchContentTextField = [[UITextField alloc] initWithFrame:CGRectMake(WIDTH(72), 0, WIDTH(560), HEIGHT(42))];
        
        _searchContentTextField.placeholder = @"搜索";
        
        _searchContentTextField.center = CGPointMake(_searchContentTextField.center.x, _searchBtnView.frame.size.height / 2.0);
    }
    
    return _searchContentTextField;
}

#pragma mark - 构造函数
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    
    if (self) {
        [self initUI];
    }
    
    return self;
}


#pragma mark - 其它函数
-(void)initUI{
    [self addSubview:self.headerView];
}

-(void)search{
    [self.searchContentTextField becomeFirstResponder];
}
@end
